home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-14 | 4.5 KB | 149 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;;Select-Rectangle.Lisp
- ;;
- ;;Copyright © 1987-89, Apple Computer, Inc
- ;;
- ;;
- ;; This file has some examples of making trap calls and using window.
- ;;
- ;; It implements a function for dragging out a gray rectangle.
- ;; Then it shows how to use this function to create a new class of windows.
- ;;
- ;
- ; Changes:
- ;
- ;20-Sep-90 mc Changed select-rectangle to be a *view* method and changed
- ; with-port to with-focused-view
- ;10-Oct-90 mc Had to add with-focused-view to
- ; (window-click-event-handler mondrian-window) (why now?).
- ; Commented out mondrian-window code.
- ; Added optional the-anchor-point arg to select-rectangle.
- ; Added provide, *features*
- ;25-May-91 mc Converted to mcl 2.0b1
- ;14-Mar-92 mc Commented out the loading of records.lisp
- ;
- ;;
-
- (in-package "CCL")
-
- (export '(SELECT-RECTANGLE))
-
-
- (pushnew :select-rectangle *features*)
- (provide :select-rectangle)
-
-
- ;;;;;;;;;;;;;;;;;;
- ;;
- ;;select-rectangle
- ;;
- ;; returns multiple values giving the two corner points of the
- ;; selected rectangle.
- ;;
-
- (defmethod select-rectangle ((self view) &optional the-anchor-point)
- "THE-ANCHOR-POINT specifies the upper left position from which the rect
- will be drawn and defaults to view-mouse-position."
- ;;
- (with-focused-view self
- ;; Type check optional args.
- (when (and the-anchor-point
- (not (integerp the-anchor-point)))
- (error "The-anchor-point ~S not a Macintosh point (integer)"
- the-anchor-point))
- ;;
- (let* ((anchor-point (or the-anchor-point (view-mouse-position self)))
- (old-mouse (view-mouse-position self))
- (new-mouse old-mouse))
- (rlet ((r :rect)
- (old-pen-state :penstate))
- (#_GetPenState :ptr old-pen-state)
- (#_PenMode :word (position :patxor *pen-modes*))
- (rset (wptr self) grafPort.pnPat *gray-pattern*)
- (#_pt2rect :long anchor-point :long new-mouse :ptr r)
- (#_FrameRect :ptr r)
- (loop
- (unless (mouse-down-p) (return)) ;return when the mouse lets up
- (unless (eq old-mouse new-mouse)
- (#_FrameRect :ptr r)
- (#_pt2rect :long anchor-point :long new-mouse :ptr r)
- (#_FrameRect :ptr r)
- (sleep 1/60)
- (setq old-mouse new-mouse))
- (setq new-mouse (view-mouse-position self)))
- (#_FrameRect :ptr r)
- (#_SetPenState :ptr old-pen-state)
- (values (rref r rect.topleft)
- (rref r rect.bottomright))))))
-
-
- #|
- ;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; mondrian-window
- ;;
- ;; a class of windows that lets you draw rectangle pictures
-
- (defclass mondrian-view (view)
- ())
-
- (defmethod view-click-event-handler ((self mondrian-view) where)
- (declare (ignore where))
- ;;
- (multiple-value-bind (topleft bottomright) (select-rectangle self ;#@(100 100)
- )
- (rlet ((my-rect :rect))
- (rset my-rect rect.topleft topleft)
- (rset my-rect rect.bottomright bottomright)
- (with-focused-view self
- (#_InvertRect :ptr my-rect)))))
-
- (defclass mondrian-window (mondrian-view window)
- ())
-
- (make-instance 'mondrian-window)
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; Selecting-scroller
- ;;
- ;; A class of windows that tests select-rectangle on nested scrollers.
-
- (require "SCROLLERS")
-
-
- (defclass scroller2 (scroller mondrian-view) ())
-
- (defmethod scroll-bar-limits ((view scroller2))
- (normal-scroll-bar-limits view 300 300))
-
- (defmethod view-draw-contents ((self scroller2))
- (frame-rect self 110 10 170 170)
- (call-next-method))
-
- (defclass scroller3 (scroller mondrian-view) ())
-
- (defmethod scroll-bar-limits ((view scroller3))
- (normal-scroll-bar-limits view 170 170))
-
- (defmethod view-draw-contents ((self scroller3))
- (paint-oval self 10 10 70 70)
- (paint-oval self 70 70 170 170)
- (call-next-method))
-
- (let* ((dial (make-instance 'dialog))
- (first-scroller (make-instance 'scroller2
- :view-container dial
- :view-size #@(180 180)
- :view-position #@(5 5)
- :track-thumb-p t))
- (second-scroller (make-instance 'scroller3
- :view-container first-scroller
- :view-size #@(75 155)
- :view-position #@(10 10)
- :track-thumb-p t)))
- (list dial first-scroller second-scroller))
-
- |#